home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 235 / Issue 235 - September 2007 - DPCS0907DVD.ISO / Extras / NetObjects Fusion / NOF10.exe / data1.cab / FSI / lib / nof / util / logging / ConsoleHandler.js next >
Encoding:
Text File  |  2007-04-11  |  3.5 KB  |  116 lines

  1. /****i* SOURCE_FILE/INFO
  2.   *
  3.   * NAME
  4.   *  ConsoleHandler.js
  5.   *
  6.   * USAGE
  7.   *  Part of Netobjects JavaScript Library.
  8.   *
  9.   * COPYRIGHT
  10.   *  Copyright ⌐ 2000-2005 Website Pros, Inc.
  11.   *  All Rights Reserved.
  12.   *
  13.   *  This is an unpublished work protected by Website Pros, Inc.
  14.   *  as a trade secret, and is not to be used or disclosed except as
  15.   *  expressly provided in a written license agreement executed by
  16.   *  you and Website Pros, Inc.
  17.   *
  18.   *      <copyright@websitepros.com>
  19.   *
  20.   * NOTES
  21.   *  JavaScript code.
  22.   *
  23.   *****/
  24.  
  25. if (!IS_isModuleInitialized("IS.NOF.UTIL.LOGGING.ConsoleHandler"))
  26. {   
  27.   /****h* NOF_JavaScript_Library/NOF.UTIL.LOGGING.ConsoleHandler
  28.     *
  29.     * NAME
  30.     *  NOF.UTIL.LOGGING.ConsoleHandler
  31.     *
  32.     * DESCRIPTION
  33.     * <code>ConsoleHandler</code> is a <code>Handler</code> designed to 
  34.     * log messages into a HTML window. It inherits all the methods provided 
  35.     * by the Handler class, plus the close() method.
  36.     * 
  37.     * var cfgLogger = NOF.UTIL.LOGGING.getLogger("myModuleName");
  38.     * var cHndl   = new NOF.UTIL.LOGGING.ConsoleHandler(cfgLogger);
  39.     * cfgLogger.addHandler( cHndl );
  40.     * cfgLogger.warning(" {0} is stronger than {1}! ", "mySourceClass", "mySourceMethod", ["Superman", "Batman"] ); 
  41.     * // ...
  42.     * try {
  43.     *   cHndl.close();
  44.     * } catch (closing_e) {
  45.     *   // ...
  46.     * }
  47.     *   
  48.     * External dependencies:
  49.     *   NOF.IO.TextElementWriter  
  50.     *
  51.     ****/
  52.   
  53.   /**
  54.   * constructor 
  55.   * Open a new console window (replace existing window with the same name)
  56.   * 
  57.   * @param logger instance of the Logger who "owns" this Handler
  58.   **/
  59.   function LOGGING_ConsoleHandler( logger ) {
  60.     this.__proto__ = LOGGING_ConsoleHandler.prototype;    
  61.     
  62.     this.SUPER(logger);
  63.     
  64.     var wndHndName = (this.logger != null) ? this.logger.getLoggerName() : "";
  65.     wndHndName = wndHndName.replace(/\./g, "_");
  66.     
  67.     this.wnd = window.open("", wndHndName, "width=670,height=430,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0");
  68.     this.wnd.document.open("text/html");
  69.     this.wnd.document.write(this.CONSOLE_WINDOW_HTML);
  70.     this.wnd.document.close();
  71.     this.wnd.document.title = wndHndName;
  72.     
  73.     this.writer = new NOF.IO.TextElementWriter(this.wnd.document["dbgFrm"].console);            
  74.     
  75.   }  
  76.   LOGGING_ConsoleHandler.inherits(LOGGING.Handler) 
  77.   {
  78.     var member = LOGGING_ConsoleHandler.prototype;    
  79.     member.CLASS_NAME        = "LOGGING.ConsoleHandler";
  80.     
  81.     member.CONSOLE_WINDOW_HTML = '<html><head><title>logging</title>\
  82.       <link rel="stylesheet" type="text/css" href="../../global.css">\
  83.       <link rel="stylesheet" type="text/css" href="catalog.css">\
  84.       </head>\
  85.       <body>\
  86.       <form name="dbgFrm">\
  87.       <textarea name="console" rows="23" cols="80" scrolling="auto"></textarea>\
  88.       <input type="button" name="clear" value="clear" onclick="this.form.console.value=\'\';">\
  89.       </form>\
  90.       </body>\
  91.       </html>';
  92.       
  93.     var method = LOGGING_ConsoleHandler.prototype;            
  94.     
  95.     /**
  96.     * Write the formatted message to the console.
  97.     * 
  98.     * @param ft formatted text
  99.     **/        
  100.     method.output = function ( /*string*/ ft) {             
  101.       this.writer.writeln(ft);
  102.     }    
  103.     
  104.     /**
  105.     * Close the console window.
  106.     * 
  107.     **/                
  108.     method.close = function () { 
  109.       try {
  110.         this.wnd.close(); 
  111.       } catch(e_ignore) {}
  112.     }
  113.   }
  114.   
  115.   LOGGING.__proto__.ConsoleHandler = LOGGING_ConsoleHandler;
  116. }